//首次安装时设置Parse表的访问权限
//http://docs.parseplatform.org/parse-server/guide/#class-level-permissions

const {appId,masterKey,serverURL}=require('../config/parse_server_config.js');

const Parse = require('parse/node');
Parse.initialize(appId, masterKey,masterKey);
Parse.serverURL = serverURL;

const axios=require("axios");

async function setAuthReadingCLP(className) {
    const authReadingCLP={
        "classLevelPermissions":{
            "get":{"requiresAuthentication":true},
            "find":{"requiresAuthentication":true},
            "count":{"requiresAuthentication":true},
            "create":{},
            "update":{},
            "delete":{}
        }
    };
    const url=`${serverURL}/schemas/${className}`;
    const response = await axios({
        method:"put",
        url,
        headers: {
            'Content-Type': 'application/json',
            'X-Parse-Application-Id': 'APPLICATION_ID',
            'X-Parse-Master-Key': 'MASTER_KEY',
            "InstallationId":"b1c9f0db-dbc4-4fcf-922f-bffb5dc00fa6",
        },
        data: authReadingCLP
    });
    return response.data;
}
async function run(){
    try{
        const classNames=["v5_comment_library","v5_emooc_student_device","v5_file","v5_name_list","v5_report","v5_report_box","v5_resource","v5_user","v5_word"];
        classNames.forEach(className=>{
             setAuthReadingCLP(className);
        })
    }catch (e) {
        console.error(e)
    }
}

run();
